package com.scetoop.bank;


public class CheckingAccount extends  Account {
    private SavingAccount protectdBy;
    //    private double overdraftProtection;
    private double OverdraftProtection = -1;

    public CheckingAccount(double init_balance) {
        super(init_balance);
//        this.overdraftProtection = 0;
    }

    public CheckingAccount(double init_balance, double overdraftProtection) {
        super(init_balance);
//        this.overdraftProtection = protect;
    }

    public void withdraw(double amt) throws OverdraftException {
        if (balance >= amt) {
            balance -= amt;
        } else {

            if(OverdraftProtection == -1){
                throw new OverdraftException("no overdraft protection",
                        amt - balance);
            }

            if (OverdraftProtection >= (amt - balance)) {
                OverdraftProtection -= (amt - balance);
            } else {
                throw new OverdraftException("Insufficient funds for overdraft protection"
                        ,amt - balance);
            }
        }
    }
}